package com.nulldev.util.web.nCaptcha.captchas.advanced;

import java.awt.image.BufferedImage;

import com.nulldev.util.image.ImageUtil;
import com.nulldev.util.image2.textobf.TextObf;
import com.nulldev.util.image2.textobf.TextObf.ObfuscationMethod;
import com.nulldev.util.java.DataSet;
import com.nulldev.util.string.StringsUtil;
import com.nulldev.util.web.nCaptcha.backend.Captcha;

public class MultiWordCheck implements Captcha {

	@Override
	public DataSet<String, String[]> generateBase64Image(int botLevel) {
		ObfuscationMethod method = ObfuscationMethod.PixelObfuscation;
		if (botLevel > 2) {
			method = ObfuscationMethod.Noise;
		}else if (botLevel > 4) {
			method = ObfuscationMethod.PixelsAndNoise;
		}
		final String word = StringsUtil.randomString(4) + " " + StringsUtil.randomString(6);
		final BufferedImage bi = TextObf.obfuscate(word, method);
		return new DataSet<String, String[]>(
				"data:image/png;base64," +  ImageUtil.convertImageDataBase64(bi), new String[] {word});
	}

	@Override
	public String getType() {
		return "multiword";
	}

}
